<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <!-- <title>登录 - 我是一阵风直播</title> -->
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
  	<style>
        .title{
            margin:2.5rem 0rem 2rem 0rem;
        }
        .login-sub {
            margin-top: 3rem;
        }
        .login-third {
            margin-top: 3rem;
        }
        .login-con{
            margin-top:2.5rem;
        }
        .aui-bar-btn-item{line-height:2rem;}
  	</style>
</head>
<body>
    <header class="aui-bar aui-bar-nav" id="aui-header">
        <!-- <div class="aui-title">登录 - 我是一阵风主播端</div> -->
    </header>
    <section class="aui-content login-con">
        <div class="aui-bar aui-bar-btn aui-bar-btn-round" style="width:80%;margin-bottom:1rem;">
            <div class="aui-bar-btn-item aui-active">账号密码登录</div>
            <div class="aui-bar-btn-item" tapmode onclick="openFrm('login_phone_frm')">手机号登录</div>
        </div>
        <ul class="aui-list aui-form-list login-btn">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label aui-border-r aui-text-center">直播账号</div>
                    <div class="aui-list-item-input aui-padded-l-10">
                        <input type="text" pattern="[0-9a-zA-Z]{5-30}" placeholder="输入账号" id="login_name" >
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label aui-border-r aui-text-center">登录密码</div>
                    <div class="aui-list-item-input aui-padded-l-10">
                        <input type="password" placeholder="输入密码" id="login_pass" >
                    </div>
                </div>
            </li>
        </ul>
    </section>
    <section class="aui-content-padded login-sub">
        <div class="aui-btn aui-btn-block aui-btn-info" tapmode onclick="fnLogin()">登录</div>
    </section>
    <section class="aui-content-padded login-third">
        <p class="aui-font-size-12 aui-text-center aui-margin-b-15">第三方账号登录</p>
        <div class="aui-grid" style="background: none;">
            <div class="aui-row">
                <div class="aui-col-xs-4">
                    <i class="aui-iconfont aui-icon-qq"></i>
                </div>
                <div class="aui-col-xs-4">
                    <i class="aui-iconfont aui-icon-wechat"></i>
                </div>
                <div class="aui-col-xs-4">
                    <i class="aui-iconfont aui-icon-alipay"></i>
                </div>
            </div>
        </div>
    </section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
    apiready = function(){
      fixStatusBar();
      api.parseTapmode();

    };

    function md5(string,callback){
       var signature = api.require('signature');
      signature.md5({
          data: string
      },callback);
    }
    /**
    *账号密码登录
    */
    function fnLogin(){
      var userName = $api.val($api.byId('login_name')),
               password = $api.val($api.byId('login_pass'));
       if (!$api.trim(userName)) {
           api.toast({
         msg: '请输入账号',
         duration: 1000,
         location: 'middle'
     });
     return;
   }
       if (!$api.trim(password)) {
           api.toast({
         msg: '请输入密码',
         duration: 1000,
         location: 'middle'
     });
     return;
   }
   /*** 加载动画 ***/
           api.showProgress({
               title : ' ',
               text : '玩命加载中...',
               modal : true
           });

           var timestamp = parseInt(new Date().getTime()/1000);

           md5(timestamp,function(ret){
             if(ret.status){
              var appid= 'live001';
              var scp='XnQp2uUaQY0f8Ln';
              var key0=appid+ret.value.toLowerCase()+scp;
              md5(key0,function(ret){
                if(ret.status){
                  api.ajax({
                    url: "https://www.qiersan.com/login/user/login",
                    method: 'post',
                    headers: {
                      'appid':'live001',
                      'time':timestamp,
                      'key':ret.value.toLowerCase()
                              },
                    data: {
                      'values':{
                        "login_name":userName,
                        "login_pass":password
                      }
                    }
                  },function(ret,err){
                    api.hideProgress();

                    //console.log($api.jsonToStr(ret));

                    if(ret.code==1){
                      api.toast({
              　　　　　　msg:'登录成功',
              　　　　　　duration: '1200',
              　　　　　　localtion: 'middle'
            　　　　　　});
                      $api.setStorage('isLogin', 1);
                      $api.setStorage('token', ret.data.token);
                      var timestamp = parseInt(new Date().getTime()/1000);

                        var token = ret.data.token;

                        md5(timestamp,function(ret){
                          if(ret.status){
                           var appid= 'live001';
                           var scp='XnQp2uUaQY0f8Ln';
                           var key0=appid+ret.value.toLowerCase()+scp;
                           md5(key0,function(ret){
                             if(ret.status){
                               api.ajax({
                                 url: "https://www.qiersan.com/user/user/find",
                                 method: 'post',
                                 headers: {
                                   'appid':'live001',
                                   'time':timestamp,
                                   'key':ret.value.toLowerCase()
                                           },
                                 data: {
                                   'values':{
                                     "token":token
                                   }
                                 }
                               },function(ret,err){
                                 //console.log($api.jsonToStr(ret.data.true_name));
                                 if(ret.code==1){
                                   $api.setStorage('phone', ret.data.phone);
                                   $api.setStorage('true_name', ret.data.true_name);
                                   $api.setStorage('headimg_url', ret.data.headimg_url);
                                   $api.setStorage('userid', ret.data.user_id);
                                 }
                                 //console.log($api.jsonToStr(ret));
                                 $api.post(baseUrl+'live/live/my_video',{
                                 body: 'String',values:{user_id:ret.data.user_id}
                               },function(ret){
                                   var newret = JSON.parse(ret);
                                 if(newret.code==1){
                                   $api.setStorage('creattime', newret.data.created_at);
                                   $api.setStorage('title', newret.data.title);
                                   $api.setStorage('rid', newret.data.rid);
                                   $api.setStorage('pushurl', newret.data.pushurl);
                                    $api.setStorage('live_cover', newret.data.live_cover);

                                 }
                               },'text');

                               });
                             }
                           });
                          }
                        });



                      setTimeout(function(){
                        window.location.href="video_frm.html";
                      },1000);
                    }else {
                      api.toast({
              　　　　　　msg:'登录失败',
              　　　　　　duration: '1200',
              　　　　　　localtion: 'middle'
            　　　　　　});
                    }
                  });
                }
              });
             }
           });

           //  $api.post(baseUrl+'login/user/login',{
           //  body: 'appid=live001;data='+timestamp+';key='+key,
           //  values:{login_name:userName,login_pass:password}
           //  },function(ret){
           //    api.hideProgress();
           //    alert(ret.msg);
           //    if(ret.code==1){
           //      setTimeout(function(){
           //        window.location.href="home_frm.html";
           //      },1000);
           //    }
           //  });



        //openFrm('home_frm');
    }
</script>
</html>
